package brouter.api.utils;

import android.text.TextUtils;

public class PathUtil {
    public static boolean checkRouterPath(String path) {
        if (TextUtils.isEmpty(path) || !path.startsWith("/")) {
            return false;
        }
        if (path.lastIndexOf("/") == 0) { // 只写了一个 /
            return false;
        }

        // 截取组名  /login/LoginActivity
        String finalGroup = path.substring(1, path.indexOf("/", 1));
        if (TextUtils.isEmpty(finalGroup)) {
            return false;
        }
        return true;
    }

    public static String parseGroup(String path) {
        // 截取组名  /login/LoginActivity  group=login
        if (checkRouterPath(path)) {
            return path.substring(1, path.indexOf("/", 1));
        }
        return "";
    }
}
